﻿#region << 文件说明 >>

/*----------------------------------------------------------------
 * 命名空间：Vampirewal.BlogCore.Controls.Form
 * 唯一标识：af1decdd-f7e4-451c-8bbb-148b3b5179e4
 * 文件名：NumInput
 *
 * 创建者：杨程
 * 电子邮箱：235160615@qq.com
 * 创建时间：2024/7/4 14:47:12
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/

#endregion << 文件说明 >>

namespace Vampirewal.BlogCore;

/// <summary>
/// 表单数字输入控件
/// <para>http://element-plus.org/zh-CN/component/input-number.html#api</para>
/// </summary>
public sealed class NumInput : ControlBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    internal NumInput()
    {
    }

    public override string Id { get; set; }
    public override string Title { get; set; }

    public override string ConverToHtml()
    {
        StringBuilder sb = new StringBuilder();

        Param par = new Param()
        {
            $":min=\"{Min}\"",
            $":max=\"{Max}\"",
            $":step=\"{Step}\"",
            $":precision=\"{Precision}\""
        };

        sb.AppendLine($"<el-input-number v-model=\"{Title}\" {par} />");

        return sb.ToString();
    }

    /// <summary>
    /// 最小值
    /// </summary>
    internal int Min { get; set; }

    /// <summary>
    /// 最大值
    /// </summary>
    internal int Max { get; set; }

    /// <summary>
    /// 精度
    /// </summary>
    internal int Precision { get; set; }

    /// <summary>
    /// 步进
    /// </summary>
    internal float Step { get; set; }
}

public static partial class App
{
    /// <summary>
    /// 创建表单数字输入框
    /// </summary>
    /// <param name="modelName"></param>
    /// <param name="min"></param>
    /// <param name="max"></param>
    /// <param name="precision"></param>
    /// <param name="step"></param>
    /// <returns></returns>
    public static NumInput CreateNumInput(string modelName, int min = 0, int max = 100, int precision = 1, float step = 1)
    {
        NumInput numInput = new NumInput()
        {
            Id = GenerateId(),
            Title = modelName,
            Step = step,
            Precision = precision,
            Min = min,
            Max = max
        };

        return numInput;
    }
}